package com.ruoyi.trackapply.component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

public class LocaionListSerializer extends JsonSerializer<List<BigDecimal>> {

    @Override
    public void serialize(List<BigDecimal> bigDecimals, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        DecimalFormat decimalFormat = new DecimalFormat();
        decimalFormat.applyPattern("0.###E0");
        int size = bigDecimals.size();
        String[] strs = new String[size];
        for (int i = 0; i < size; i++) {
            strs[i]=decimalFormat.format(bigDecimals.get(i)).replace("E0","");
        }
        jsonGenerator.writeArray(strs,0,size);
    }
}
